import 'package:mobile_device_identifier/mobile_device_identifier.dart';
import 'dart:async';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DeviceUtils {
  static String _deviceId = '';
  static final _mobileDeviceIdentifierPlugin =
      MobileDeviceIdentifier(); // 改为静态成员

  // 使用 ScreenUtil 的 sp 单位进行字体适配（推荐）
  static double width2 = 2.sp;
  static double width3 = 3.sp;
  static double width4 = 4.sp;
  static double width6 = 6.sp;
  static double width8 = 8.sp;
  static double width10 = 10.sp;
  static double width12 = 12.sp;
  static double width14 = 14.sp;
  static double width16 = 16.sp;
  static double width18 = 18.sp;
  static double width20 = 20.sp;
  static double width24 = 24.sp;
  static double width28 = 28.sp;
  static double width32 = 32.sp;
  static double width36 = 36.sp;
  static double width100 = 100.sp;
  static double width200 = 200.sp;

  // 新增：使用 flutter_screenutil 的适配方法（推荐）
  static double adaptiveSizeByScreenUtil(double width) {
    return width.sp;
  }

  static Future<String> getDeviceId() async {
    if (_deviceId.isNotEmpty) {
      return _deviceId;
    }

    try {
      _deviceId =
          await _mobileDeviceIdentifierPlugin.getDeviceId() ??
          'Unknown platform version';
    } catch (e) {
      _deviceId = 'Failed to get platform version.';
    }

    return _deviceId;
  }
}
